package activity.login;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.hutoubenjg.R;

import java.util.Observable;
import java.util.Observer;

import base.BaseActivity;
import presenter.UserPresenter;
import util.utls.ByAlert;
import util.utls.IsUtilUid;
import util.volley.ResultEntity;

/**
 * @name 忘记密码
 * Created by itboye on 2016/12/5.
 */

public class ActivityForgetPassword extends BaseActivity implements Observer {
    private Button btnNext;
    private ImageView back;
    private TextView tvTitle;
    private TextView tvTest;
    EditText passwprd_one_tel;
    Button passwprd_one_ok;
    UserPresenter userPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forget_passorld);
        tvTitle.setText("忘记密码");
        tvTest.setVisibility(View.GONE);
        userPresenter = new UserPresenter(this);
    }

    @Override
    protected void onInit() {

    }

    @Override
    protected void onReadIntent(Bundle bundle) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back:
                this.finish();
                break;
            case R.id.passwprd_one_ok:
                if (passwprd_one_tel.getText().toString().length()!=11) {
                    ByAlert.alert("请输入正确的电话号码！");
                    return;
                }

                showProgressDialog("请稍后...",true);
                userPresenter.sendVerificationCode("+86", passwprd_one_tel.getText().toString(), 2 + "");

                break;
            default:
                break;
        }
    }


    @Override
    public void update(Observable observable, Object data) {
        ResultEntity entity = handlerError(data);
        if (entity != null) {
            IsUtilUid.tianjia(entity);
            if (entity.getEventType() == UserPresenter.send_code_success) {
                ByAlert.alert(entity.getData());
                Intent intent = new Intent(this, ActivityVerficationCode.class);
                intent.putExtra("phone", passwprd_one_tel.getText().toString());
                startActivity(intent);
                finish();
            }
            if (entity.getEventType() == UserPresenter.send_code_fail) {
               ByAlert.alert(entity.getData());
            }
        }
        try {
            closeProgressDialog();
        } catch (Exception e) {
        }
    }
}
